<!DOCTYPE html SYSTEM "http://www.thymeleaf.org/dtd/xhtml1-strict-thymeleaf-spring4-4.dtd">

<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:th="http://www.thymeleaf.org" >

<head>
    <meta charset="UTF-8">
    <title>轮播图</title>
</head>
<script type="text/javascript" th:src="@{/js/jquery-2.1.4.min.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap-3.3.7-dist/js/bootstrap.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootstrap-3.3.7-dist/css/bootstrap.min.css}">
<script type="text/javascript" th:src="@{/js/bootstrap-treeview/bootstrap-treeview.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootstrap-treeview/bootstrap-treeview.min.css}">
<script type="text/javascript" th:src="@{/js/bootStrap-addTabs/bootstrap.addtabs.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootStrap-addTabs/bootstrap.addtabs.css}">
<script type="text/javascript" th:src="@{/js/bootstrap-table/bootstrap-table.min.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap-table/locale/bootstrap-table-zh-CN.min.js}"></script>
<link type="text/css" rel="stylesheet" th:href="@{/js/bootstrap-table/bootstrap-table.min.css}">
<link type="text/css" rel="stylesheet" th:href="@{/js/bootstrap-fileinput/css/fileinput.css}">

<script type="text/javascript" th:src="@{/js/bootstrap-bootbox/bootbox.js}"></script>
<script type="text/javascript" th:src="@{/js/bootstrap-fileinput/js/fileinput.min.js}"></script>
<script th:src="@{/js/bootstrap-fileinput/js/locales/zh.js}"></script>

<body>
<table id="myTable">

</table>
<!-- 修改模态框（Modal） -->
<div class="modal fade" id="myModal1" tabindex="-1" role="dialog" aria-labelledby="myModalLabel1" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                <h4 class="modal-title" id="myModalLabel1">修改商品</h4>
            </div>
            <div class="modal-body">
                <form id="myForm1">
                    <input type="hidden" class="form-control" name="id"id="id"  >
                    商品图片：<input id="file-Portrait" name="img" class="form-control" type="file">
                </form>
            </div>
            <!--  ====================================================   -->

            <div class="modal-footer">
                <button data-dismiss="modal" class="btn btn-default" type="button">关闭</button>
                <button class="btn btn-primary" type="button" onclick="sub()">确认修改</button>
            </div>
        </div><!-- /.modal-content -->
    </div><!-- /.modal -->
</div>
</body>
<script type="text/javascript">

    $("#myTable").bootstrapTable({
        url:"getBanner",
        columns:[
            {field:"xuan",checkbox:true},
            {field:"id",title:"编号"},
            {field:"img",title:"商品图片",formatter:function(value,row,index){
                    return "<img width='50px' height='50px' src='"+value+"'>";
                }},
            {field:"cxz",title:"操作",formatter:function(value,row){
                    var str2='<button class="btn btn-primary" onclick="getProId('+row.id+')" data-toggle="modal" data-target="#myModal1">修改</button>';
                    return str2;
                }},
        ],
        pagination:true,
        pageSize:10,
        pageList:[2,4,6,8,10],
        sidePagination: "client",
        toolbar:"#tb",
    })

    //修改回显
    function getProId(id){
        $.ajax({
            url:"geIdBan",
            data:{id:id},
            type:"post",
            dataType:"json",
            success:function(data){

                $("#id").val(data.id);
                $("#img").val(data.img);
                $("#file-Portrait").fileinput('refresh', {
                    initialPreview: "<img src="+data.img+" height='180px' width='150px' class='file-preview-image'>",
                });
            }
        })
    }
    //修改
    function sub(){
        $.ajax({
            url:"updBan",
            type:"post",
            data:$("#myForm1").serialize(),
            success:function(){
                $('#myTable').bootstrapTable('refresh');//刷新表格
                $("#myModal1").modal('hide');

            },error:function(){
                $('#myTable').bootstrapTable('refresh');//刷新表格
                $("#myModal1").modal('hide');
            }
        })
    }
    //图片上传
    $('#file-Portrait').fileinput({
        language: 'zh', //设置语言
        uploadUrl: "upload1", //上传的地址
        allowedFileExtensions : ['jpg', 'png','gif'],//接收的文件后缀,
        maxFileCount: 100,
        enctype: 'multipart/form-data',
        showUpload: true, //是否显示上传按钮
        showCaption: false,//是否显示标题
        browseClass: "btn btn-primary", //按钮样式
        previewFileIcon: "<i class='glyphicon glyphicon-king'></i>",
        msgFilesTooMany: "选择上传的文件数量({n}) 超过允许的最大数值{m}！",

    });
</script>
</html>